home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-13 | 2.3 KB | 146 lines | [TEXT/EDIT] |
- -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C)
- -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
- --
- class LINK_LIST[E]
- --
- -- One way linked list.
- --
-
- inherit COLLECTION[E];
-
- creation {ANY}
- make, from_array
-
- feature
-
- lower: INTEGER is 1;
- -- Lower index bound.
-
- upper: INTEGER;
- -- Upper index bound.
-
- feature {NONE}
-
- first_link: LINK[E];
-
- last_i: INTEGER;
- -- When greater than 0, the last access done memorized
- -- in `last_link'.
-
- last_link: like first_link;
-
- feature -- Creation and Modification :
-
- make is
- do
- first_link := Void;
- upper := 0;
- last_i := 0;
- ensure
- count = 0
- end;
-
- from_array(a: ARRAY[E]) is
- require
- a /= Void
- local
- i: INTEGER;
- do
- if first_link = Void then
- from
- i := a.upper;
- until
- i < a.lower
- loop
- !!first_link.make(a.item(i),first_link);
- i := i - 1;
- end;
- upper := a.upper;
- else
- not_yet_implemented;
- end;
- if a.count > 0 then
- last_link := first_link;
- last_i := 1;
- else
- last_link := Void;
- last_i := 1;
- end;
- ensure
- count = a.count
- end;
-
- feature -- Accessing :
-
- infix "@", item(index: INTEGER): E is
- do
- go_item(index);
- Result := last_link.item;
- end;
-
- feature -- Modification :
-
- put(element: E; index: INTEGER) is
- do
- go_item(index);
- last_link.set_item(element);
- end;
-
- add_first(e: E) is
- do
- !!first_link.make(e,first_link);
- upper := upper + 1;
- last_i := 1;
- last_link := first_link;
- end;
-
- copy(other: like Current) is
- -- Copy `other' onto Current.
- local
- i: INTEGER;
- do
- from
- i := 1;
- last_i := 1;
- last_item := first_link;
- until
- i > other.upper
- loop
- not_yet_implemented;
- put(other.item(i),i);
- i := i - 1;
- end;
- end;
-
- feature {NONE}
-
- go_item(i: INTEGER) is
- require
- valid_index(i)
- do
- if i = last_i then
- else
- if last_i > i then
- last_i := 1;
- last_link := first_link;
- end;
- from
- until
- i = last_i
- loop
- last_link := last_link.next;
- last_i := last_i + 1;
- end;
- end;
- ensure
- last_i = i
- end;
-
- invariant
-
- upper = 0 implies first_link = Void;
-
- first_link = Void implies upper = 0;
-
- end -- LINK_LIST[E]
-